import router from './router'
import store from './store'
import axios from 'axios'
export default function setAxios(){
    axios.interceptors.request.use(config=>{
        if(store.state.token){
            config.headers.token=store.state.token
        }
        return config
    })
    axios.interceptors.response.use(response=>{
        if(response.status===200){
            const data=response.data
            if(data.code===-1){
                store.commit('setToken','')
                window.localStorage.removeItem('token')
                router.replace('/login')
            }
            return data
        }
        return response
    })
}